#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define NOISY_TEST 0
#define WHICH_WAY 1

char inputChar()
{
    char randChar = (char)(rand() % 94 + 32);	//generates random ASCII values beginning with "space" up through "closed curly brace"
  	return randChar;							//returns the ASCII character
}

char *inputString()
{
    #if (WHICH_WAY == 0)							//option "0"
    	int i;							
    	char *randString = malloc(sizeof(char) * 6);	
  		for(i=0; i < 5; i++){
  			randString[i] = (char)(rand() % 25 + 97);	
  		}
		randString[5] = '\0';

  		//free(randString);

  		return randString;
  	#endif

  	#if (WHICH_WAY == 1)							//option "1"
  		int i;
        static char randString[6];					
        for(i = 0; i < 5; i++){
            randString[i] = rand() % 25 + 97;
        }
        randString[5] = '\0';

        return randString;

  	#endif

}

void testme()
{
  int tcCount = 0;
  char *s;
  char c;
  int state = 0;
  while (1)
  {
    tcCount++;
    c = inputChar();
    s = inputString();

    #if (NOISY_TEST == 1)
    	printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state);
    #endif

    if (c == '[' && state == 0) state = 1;
    if (c == '(' && state == 1) state = 2;
    if (c == '{' && state == 2) state = 3;
    if (c == ' '&& state == 3) state = 4;
    if (c == 'a' && state == 4) state = 5;
    if (c == 'x' && state == 5) state = 6;
    if (c == '}' && state == 6) state = 7;
    if (c == ')' && state == 7) state = 8;
    if (c == ']' && state == 8) state = 9;
    if (s[0] == 'r' && s[1] == 'e'
       && s[2] == 's' && s[3] == 'e'
       && s[4] == 't' && s[5] == '\0'
       && state == 9)
    {
      #if (NOISY_TEST == 0)
		  printf("Iteration %d: c = %c, s = %s, state = %d\n", tcCount, c, s, state);
      #endif
      printf("error ");
      exit(200);
    }
  }
}


int main(int argc, char *argv[])
{
    srand(time(NULL));
    testme();
    return 0;
}
